package com.internal.Search.server;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.ui.SuggestOracle;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
import com.internal.Internalhibernate.client.AdmProfessions;
import com.internal.Internalhibernate.server.dao.AdmProfessionsDAO;
import com.internal.Search.client.ProDisplaySuggestion;
import com.internal.Search.client.ProSuggestion;

public class SearchServerUtil {
	
	public static ProSuggestion getProSuggest(SuggestOracle.Request request){
		ProSuggestion proSuggestion=new ProSuggestion();
		
		AdmProfessionsDAO admProfessionsDAO=new AdmProfessionsDAO();
		List<AdmProfessions> admProfessions=admProfessionsDAO.findProByName(request.getQuery());
		System.out.println("admProfessions "+admProfessions.size());
		List<Suggestion> suggestions=new ArrayList<SuggestOracle.Suggestion>();
		
		List<AdmProfessions> admProfessions2=new ArrayList<AdmProfessions>();
		
		for (int i = 0; i < admProfessions.size(); i++) {
			AdmProfessions admProfessions3=new AdmProfessions();
			admProfessions3.setProfession(admProfessions.get(i).getProfession());
			admProfessions3.setProfessionE(admProfessions.get(i).getProfessionE());
			admProfessions3.setProId(admProfessions.get(i).getProId());
			admProfessions2.add(admProfessions3);
			suggestions.add(new ProDisplaySuggestion(admProfessions3.getProfession()));
			
			
		}
		final SuggestOracle.Response resp = new SuggestOracle.Response();
		proSuggestion.setAdmProfessions(admProfessions2);
		resp.setSuggestions(suggestions);
		proSuggestion.setResponse(resp);
		
		return proSuggestion;
	}
	


}
